|
Thread 1
|
Thread 2
|
/* Set the CRYP parameters */
hcryp.Instance = AES;
/* Set the CRYP parameters */
hcryp.Init.DataType = CRYP_BYTE_SWAP;
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
hcryp.Init.pKey = AESKey128;
hcryp.Init.Algorithm = CRYP_AES_ECB;
HAL_CRYP_Init(&hcryp);
/* Low prio block Encryption */
HAL_CRYP_Encrypt_IT(&hcryp, Plaintext_8, 128, Encryptedtext);
/* request suspension */
HAL_CRYP_ProcessSuspend(&hcryp);
/* Suspend low prio block processing */
HAL_CRYP_Suspend(&hcryp);
/* -- Thread 1 released the AES peripheral and informed Thread 2 ---> */
/* Resume low prio block processing */
HAL_CRYP_Resume(&hcryp);
|
/* */
/* <--- Thread 2 asks to use the AES peripheral for a high-priority task -- */
/* High priority block processing */
/* Set the CRYP parameters */
hcryp.Init.DataType = CRYP_BIT_SWAP;
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
hcryp.Init.pKey = AESKey256;
hcryp.Init.pInitVect = AESIV;
hcryp.Init.Algorithm = CRYP_AES_CTR;
HAL_CRYP_Init(&hcryp);
/* Decrypt */
HAL_CRYP_Decrypt_IT(&hcryp, CiphertextAESCTR256_HighPrio,
16, Decryptedtext_HighPrio);
/* <--- Thread 1 releases the AES peripheral so that the low-priority task can resume -- */
|
|
|
Thread 1
|
Thread 2
|
/* Set the AES parameters */
HAL_AES_Init(&haes,HAL_AES);
HAL_AES_ECB_SetConfig(&haes);
HAL_AES_SetDataSwapping(&haes, HAL_AES_DATA_SWAPPING_BYTE);
HAL_AES_SetNormalKey(&haes, HAL_AES_KEY_SIZE_128BIT, AESKey128);
/* Low prio block Encryption */
HAL_AES_Encrypt_IT(&haes, Plaintext_8, 128 , Encryptedtext);
/* request suspension */
HAL_AES_RequestSuspend(&haes);
/* --------------------- Wait for suspend callback -------------------*/
/* Suspend low prio block processing */
HAL_AES_SaveContext(&haes,&p_context);
/* -- Thread 1 released the AES peripheral and informed Thread 2 ---> */
/* Restore process1 context */
HAL_AES_RestoreContext(&haes, &p_context);
/* Resume low prio block processing */
HAL_AES_Resume(&haes);
|
/* */
/* <--- Thread 2 asks to use the AES peripheral for a high-priority task -- */
/* High priority block processing */
/* Set the CRYP parameters */
HAL_AES_CTR_SetConfig(&haes,AESIV);
HAL_AES_SetDataSwapping(&haes, HAL_AES_DATA_SWAPPING_BIT);
HAL_AES_SetNormalKey(&haes, HAL_AES_KEY_SIZE_256BIT, AESKey256);
/* Decrypt */
HAL_AES_Decrypt_IT(&haes, CiphertextAESCTR256_HighPrio,
16, Decryptedtext_HighPrio);
/* --------------------- Wait for decrypt complete callback -------------------*/
/* <--- Thread 1 releases the AES peripheral so that the low-priority task can resume -- */
|
|